<?php
class Database{
    public $connect;
    public $servername = "localhost";
    public $username = "root";
    public $password = "";
    public $dbname = "php-itq";
    public $table = "note";

    public function __construct(){
        $link = mysql_connect($this->servername, $this->username, $this->password);
        if(!$link){
            die('Erro');
        }else{
            $this->connect=$link;
            $this->servername;
            $this->dbname;
            $this->table;
            $this->query("SET NAMES 'utf8'");
            $this->query("SET CHARACTER SET 'utf8'");
        }
    }

    public function setConnect($connect){
        $this->connect = $connect;
    }
    public function setDatabase(){
        mysql_select_db($this->dbname,$this->connect);
    }
    public function query($query){
        $this->resultQuery = mysql_query($query, $this->connect);
        return $this->resultQuery;
    }
    public function setTable($table){
        $this->table = $table;
    }

    public function insert(){
        $query = "insert into`$this->dbname`.`$this->table`(`title` ,`content`)value('1',  '12')";
        $this->query($query);
    }
    public function update(){
        $query = "UPDATE  `$this->dbname`.`$this->table` SET  `title` =  '123' WHERE  `note`.`id` =14";
        $this->query($query);
        echo '<pre>';
        var_dump($this->query($query));
    }
    public function delete($id){
        echo $query = "DELETE FROM `$this->dbname`.`$this->table` WHERE `$this->table`.`id` = $id";
        $this->query($query);
    }

    public function select(){
        // đời sợ nhât quên dòng này
        $this->setDatabase();
        // đời sợ nhât quên dòng này
        $result = mysql_query("SELECT * FROM note");
        $note = null;
        while($row = mysql_fetch_array( $result )) {
            $note[]=$row;
        }
        return $note;
    }
}   
 $database = new Database();
//$database->insert();
//$database->update();
//$database->delete($id=15);
//$data = $database->select();
//echo '<pre>';
//print_r($data);